#!/usr/bin/env python

starting_time=77025.764199659; #a reference to offset arrival timestamp
A=13.2; #starting delay value, in us
B=259; #max delay, in us
C=136; #start delay after loss, in us

k=620069.577145296; #increaseing rate, now delta x in s, delta y in us
asr = 887.1+99.081; #aggregate sending rate, in Mb/s
ass = 978.24; #average service rate, in Mb/s
l=1.35e-4; #time duration for packet loss burst, in s
m=float(B-C)/k; #time duration for delay in the middle
s=float(B-A)/k; #time duration for delay in the beginning

print "l=%f, m=%f, s=%f\n"%(l,m,s);

#num_delay_given_loss = [0]*(max_array_length);

#I/O
fi = open("/Volumes/Data/gSVN/ethernet-switch/script/simulation/900_700_arrival_time.txt", "r");
fh = open("/Volumes/Data/gSVN/ethernet-switch/script/simulation/ng_900_700_output.txt", "w")

print "Hello, World!" 

for line in fi:
	t=float(line);
	x=t-starting_time;
		
	if(x>=0 and x<=s):
		y=A+k*x;
	else:
		#remove periods
		n=int((x-s)//(l+m));
		#print "n = %d, x=%f\n"%(n, x)
		x=x-s-n*(l+m);
		if(x>=0 and x<l):
			y=0;
		elif(x>=l and x<=l+m):
			y=C+k*(x-l);
		else:
			print "wrong to reach here\n";
			
	out = str(t) + ' ' + str(y) + '\n';
	fh.write(out);

fi.close();
fh.close();